package cn.hxsteel.storage.module.sum;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.hxsteel.jtool.util.TimeUtil;
import cn.hxsteel.model.bo.ViewBO;
import cn.hxsteel.model.vo.PageVO;
import cn.hxsteel.purview.model.vo.SessionVO;
import cn.hxsteel.storage.core.base.BaseService;
import cn.hxsteel.storage.core.tool.DepotTool;
import cn.hxsteel.storage.model.bo.SumDayDepotBO;
import cn.hxsteel.storage.model.bo.SumTotalDepotBO;
import cn.hxsteel.storage.model.dao.CompanyDAO;
import cn.hxsteel.storage.model.dao.DepotDAO;
import cn.hxsteel.storage.model.dao.SumDayDepotDAO;
import cn.hxsteel.storage.model.dao.SumTotalDepotDAO;
import cn.hxsteel.storage.model.po.CustomerPO;
import cn.hxsteel.storage.model.vo.DepotVO;
import cn.hxsteel.storage.model.vo.SelectOptionVO;

/**
 * 统计库存的服务类
 */
@Service
class SumService extends BaseService
{
    @Autowired
    SumTotalDepotDAO _sumTotalDepotDAO;
    @Autowired
    SumDayDepotDAO   _sumDayDepotDAO;
    @Autowired
    DepotDAO         _depDepotDAO;
    @Autowired
    CompanyDAO       _companyDao;
    
    /* 总库存方法
    --------------------------------------------------*/
    
    /**
     * 查询总库存分页列表
     * 
     * @param pageNo 页码
     * @param pageSize 每页记录数
     * @param sumDate 统计日期（格式：yyyy-MM-dd）
     * @param uid 创始人标识
     * @param companyID 公司标识
     * @param depotID 仓库标识
     * @return
     */
    public List< SumTotalDepotBO > searchSumTotalDepotData( int pageNo, int pageSize, String sumDate, int uid, int companyID, int depotID )
    {
	if ( sumDate == null || sumDate.equals( "" ) )
	{
	    sumDate = TimeUtil.getTime( TimeUtil.DATE );
	}
	PageVO< SumTotalDepotBO > pageVO = _sumTotalDepotDAO.selSumTotalDepotList( pageNo, pageSize, sumDate, uid, companyID, depotID );
	super.savePagerData( pageVO );
	return pageVO.getResult();
    }
    
    /* 日库存方法
    --------------------------------------------------*/
    
    /**
     * 查询日库存列表
     * 
     * @param pageNo 页码
     * @param pageSize 每页记录数
     * @param startDate 开始日期（格式：yyyy-MM-dd）
     * @param endDate 结束日期（格式：yyyy-MM-dd）
     * @param uid 创始人标识
     * @param companyID 公司标识
     * @param depotID 仓库标识
     * @return
     */
    public List< SumDayDepotBO > searchSumDayDepotData( int pageNo, int pageSize, String startDate, String endDate, int uid, int companyID, int depotID )
    {
	if ( startDate == null || startDate.equals( "" ) )
	{
	    startDate = TimeUtil.getTime( TimeUtil.DATE );
	}
	if ( endDate == null || endDate.equals( "" ) )
	{
	    endDate = TimeUtil.getTime( TimeUtil.DATE );
	}
	PageVO< SumDayDepotBO > pageVO = _sumDayDepotDAO.selSumDayDepotPage( pageNo, pageSize, startDate, endDate, uid, companyID, depotID );
	super.savePagerData( pageVO );
	return pageVO.getResult();
    }
    
    /* 公共方法
    --------------------------------------------------*/
    
    /**
     * 查询统计库存视图对象
     * 
     * @param 会话的值对象
     * @return
     */
    public ViewBO searchSumDepotViewBO( SessionVO< CustomerPO > sessionVO )
    {
	ViewBO res = new ViewBO();
	
	res.put( "sumDate", TimeUtil.getTime( TimeUtil.DATE ) );
	res.put( "depot", _selDepotList() );
	res.put( "showDepot", _showDepot( sessionVO ) );
	res.put( "showCompany", _showDepot( sessionVO ) );
	res.put( "showCompanyFormKind", 2 );
	res.put( "companyID", 0 );
	res.put( "uid", 10 );
	return res;
    }
    
    /**
     * 查询公司列表
     * 
     * @param uid 创始人标识
     * @param name 公司名称
     * @return
     */
    public List< SelectOptionVO > selCompanyList( int uid, String name )
    {
	return _companyDao.selCompanyList( uid, name );
    }
    
    /* 私有方法
    --------------------------------------------------*/
    
    /**
     * 查询二级仓库列表
     * 
     * @return
     */
    private List< DepotVO > _selDepotList()
    {
	return DepotTool.giveDepotList( _depDepotDAO.selDepotList() );
    }
    
    /**
     * 是否显示仓库
     * 
     * @param 会话的值对象
     * @return
     */
    private boolean _showDepot( SessionVO< CustomerPO > sessionVO )
    {
	return true;
    }
}